﻿using System.Collections.Generic;
using Mono.Cecil;
using OpenReflect.Domain.Contracts;
using OpenReflect.Domain.Model;

namespace OpenReflect.Services.Builders
{
	public interface IAssemblyBuilder
	{
		INamespaceBuilder NamespaceBuilder { get; }

		IClassBuilder ClassBuilder { get; }

		IAssemblyReferenceBuilder AssemblyReferenceBuilder { get; }

		IAssembly CreateAssembly(string path);
	}

	public class AssemblyBuilder : IAssemblyBuilder
	{
		public AssemblyBuilder(INamespaceBuilder namespaceBuilder, IClassBuilder classBuilder,
		                       IAssemblyReferenceBuilder assemblyReferenceBuilder)
		{
			NamespaceBuilder = namespaceBuilder;
			AssemblyReferenceBuilder = assemblyReferenceBuilder;
			ClassBuilder = classBuilder;
		}

		#region IAssemblyBuilder Members

		public IAssembly CreateAssembly(string path)
		{
			IAssembly retVal = new Assembly(); // to be refactored into IOC

			AssemblyDefinition definition = AssemblyFactory.GetAssembly(path);

			retVal.AssemblyName = definition.Name.FullName;

			// Build References
			IList<IAssemblyReference> references = AssemblyReferenceBuilder.CreateAssemblyReferences(definition.MainModule);

			// Build Namespaces

			// Build Interfaces

			return null;
		}

		public INamespaceBuilder NamespaceBuilder { get; private set; }

		public IClassBuilder ClassBuilder { get; private set; }

		public IAssemblyReferenceBuilder AssemblyReferenceBuilder { get; private set; }

		#endregion
	}
}